<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

    </head>
    <body>
        <f:view>
            <h:form>
                <h2>Logged in Viewer Page: <h:outputText value="#{login_bean.username}"/>, you are successfully login.</h2>
            </h:form>
        </f:view>
        
                
        <table width="800" border="1" cellspacing="0" cellpadding="2" style="margin-top: 20px">
        <%@ page import="java.util.*" %>
        <%@ page import="javax.sql.*;" %>
        <% 

        java.sql.Connection con;
        java.sql.Statement s;
        java.sql.ResultSet rs;
        java.sql.PreparedStatement pst;

        con=null;
        s=null;
        pst=null;
        rs=null;

        // Remember to change the next line with your own environment 
        String url= 
        "jdbc:mysql://localhost:3306/db_jsf";
        String id= "root";
        String pass = "";
        try{

        Class.forName("com.mysql.jdbc.Driver");
        con = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/db_jsf","root","");

        }catch(ClassNotFoundException cnfex){
        cnfex.printStackTrace();

        }
        String sql = "SELECT * FROM db_jsf.event";
        try{
        s = con.createStatement();
        rs = s.executeQuery(sql);
        %>
        <tr>
            <td>ID</td>
            <td>Event Name</td>
            <td>Start Time</td>
            <td>End Time</td>
            <td>Duration(min)</td>
            <td>Surpervisor</td>
            <td>detail</td>
        </tr>
        <%
        while( rs.next() ){
        %><tr>
        <td><%= rs.getString("ID") %></td>
        <td><%= rs.getString("EventName") %></td>
        <td><%=rs.getString(2).toString()%></td>
        <td><%=rs.getString(3).toString()%></td>
        <td><%=rs.getString(4).toString()%></td>
        <td><%=rs.getString(5).toString()%></td>
        <td><button type="button">Details</button></td>
        </tr>
        <%
        }
        %>

        <%

        }
        catch(Exception e){e.printStackTrace();}
        finally{
        if(rs!=null) rs.close();
        if(s!=null) s.close();
        if(con!=null) con.close();
        }

        %>

                 
        </tr>
                  
     
        </table>
    </body>
</html>